package com.cskaoyan.shopping.service.impl;

import com.cskaoyan.mall.commons.exception.ExceptionProcessorUtils;
import com.cskaoyan.mall.constant.ShoppingRetCode;
import com.cskaoyan.shopping.converter.ContentConverter;
import com.cskaoyan.shopping.converter.PanelPanelDtoConverter;
import com.cskaoyan.shopping.dal.entitys.PanelContent;
import com.cskaoyan.shopping.dal.persistence.PanelContentMapper;
import com.cskaoyan.shopping.dto.NavListResponse;
import com.cskaoyan.shopping.dto.PanelContentDto;
import com.cskaoyan.shopping.service.IContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.ArrayList;
import java.util.List;
@Service
public class IContentServiceImpl implements IContentService {
    @Autowired
    PanelContentMapper panelContentMapper;
    @Autowired
    ContentConverter contentConverter;
    @Override
    public NavListResponse queryNavList() {
        NavListResponse navListResponse = new NavListResponse();
        try {
            List<PanelContentDto> pannelContentDtos = new ArrayList<>();
            Example example=new Example(PanelContent.class);
            Example.Criteria criteria = example.createCriteria();
            criteria.andEqualTo("panelId",0);
            List<PanelContent> panelContents = panelContentMapper.selectByExample(example);

            for (PanelContent panelcontent :
                    panelContents) {
                PanelContentDto panelContentDto = contentConverter.panelContent2Dto(panelcontent);
                pannelContentDtos.add(panelContentDto);
            }

            navListResponse.setPannelContentDtos(pannelContentDtos);
            navListResponse.setCode(ShoppingRetCode.SUCCESS.getCode());
            navListResponse.setMsg(ShoppingRetCode.SUCCESS.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            ExceptionProcessorUtils.wrapperHandlerException(navListResponse, e);
        }
        return navListResponse;
    }
}
